#include "sqlite3/sqlite3.h"

#include <stdio.h> 


void do_show_sample(sqlite3 *db)
{
  char **result, *errmsg;
 int nrow, ncolumn, i, j, index;

 if (sqlite3_get_table(db, "select * from airlineCompany", &result, &nrow, &ncolumn, &errmsg) != 0)
 {
  printf("error : %s\n", errmsg);
  sqlite3_free(errmsg);
 }
 index = ncolumn;
 for (i=0; i<nrow; i++)
 {
  for (j=0; j<ncolumn; j++)
  {
   printf("%-8s : %-8s\n", result[j], result[index]);   
   index++;
  }
  printf("************************\n");
 }
 sqlite3_free_table(result);
 return;
}


int main()
{
    int ret;
    int operate;
    sqlite3 *db = NULL;
    char *errmsg = NULL;
    
    ret = sqlite3_open("./db/test.db", &db);
    if(ret)
    {
        printf("can not open database.\n");
    }
    else  // return 0 -> success
    {
        printf("open database success.\n");
    }
    //operate =  sqlite3_exec(db, "create table flag(flag TEXT);", 0, 0, &errmsg);
    //printf("exec_ret: %d\n", insert);
    //printf("errMsg: %s\n", errmsg);

	do_show_sample(db);
	
	
	    
    sqlite3_close(db);
 
    return 0;
}
